/*
异步调用数据库读写
*/
const mysql = require("mysql");
const config = require("../config.js");

var db = mysql.createConnection(config.db);

db.async = {};

// 数据库封装
db.async.query = (sql, params, level = 1) => {
    return new Promise((resolve, reject) => {
        // console.log(sql);
        // console.log(params);
        db.query(sql, params, (err, rows) => {
            // console.log(rows);
            resolve({ err, rows });
        });
    });
};

module.exports = { db };
